﻿using System;
using System.Security.Cryptography;

namespace ZeldaEncrypter
{
    /// <summary>
    /// This class provides static methods for generating random numbers
    /// </summary>
    internal static class RNGProvider
    {
        /// <summary>
        /// Generates secure UInt64 values with the gelp of the RNGCryptoServiceProvider
        /// </summary>
        /// <returns>A random, securely generated UInt64 value</returns>
        internal static ulong GetRandomUInt64()
        {
            // Create a new byte array with the byte length of an UInt64
            byte[] CryptoBytes = new byte[sizeof(ulong)];
            // We need a RNGCryptoServiceProvider to get secure byte values (System.Random CANNOT do this!)
            RNGCryptoServiceProvider CryptoGen = new RNGCryptoServiceProvider();
            // Let's fill our byte array with secure bytes
            CryptoGen.GetBytes(CryptoBytes);
            // Return the byte array as a UInt64 value
            return BitConverter.ToUInt64(CryptoBytes, 0);
        }
    }
}
